package com.googlecode.wmlynar.gwtbeans.gen;

public class ReferenceMappingFactory {

    //  <mapping>
    //    <class-a>com.googlecode.wmlynar.gwtbeans.gen.Bean1</class-a>
    //    <class-b>com.googlecode.wmlynar.gwtbeans.gen.Bean2</class-b>
    //    <field>
    //      <a>bean1.string1</a>
    //      <b>string2</b>
    //    </field>
    //  </mapping>

    public static com.googlecode.wmlynar.gwtbeans.gen.Bean2 copy(
            final com.googlecode.wmlynar.gwtbeans.gen.Bean1 in,
            final com.googlecode.wmlynar.gwtbeans.gen.Bean2 out) {
        out.setString2(in.getBean1().getString1());
        return out;
    }

    public static com.googlecode.wmlynar.gwtbeans.gen.Bean1 copy(
            final com.googlecode.wmlynar.gwtbeans.gen.Bean2 in,
            final com.googlecode.wmlynar.gwtbeans.gen.Bean1 out) {
        if (out.getBean1() == null) {
            out.setBean1(new com.googlecode.wmlynar.gwtbeans.gen.Bean1());
        }
        out.getBean1().setString1(in.getString2());
        return out;
    }

    // clone function

    // not needed, can be obtained by using just copy in following way:
    //
    // obj2 = copy(obj1, new Obj2())
    //
    // ACUTALLY NEEDED -> in order to deep copy arrays type needs to be determined at runtime
    //
    //    public static Object map(final com.googlecode.wmlynar.gwtbeans.gen.Bean2 in, final Class c) {
    //        if (c == com.googlecode.wmlynar.gwtbeans.gen.Bean1.class) {
    //            final com.googlecode.wmlynar.gwtbeans.gen.Bean1 out = new com.googlecode.wmlynar.gwtbeans.gen.Bean1();
    //            copy(in, out);
    //            return out;
    //        }
    //        throw new RuntimeException("Cannot map class");
    //    }
    //
    //    public static Object map(final com.googlecode.wmlynar.gwtbeans.gen.Bean1 in, final Class c) {
    //        if (c == com.googlecode.wmlynar.gwtbeans.gen.Bean2.class) {
    //            final com.googlecode.wmlynar.gwtbeans.gen.Bean2 out = new com.googlecode.wmlynar.gwtbeans.gen.Bean2();
    //            copy(in, out);
    //            return out;
    //        }
    //        throw new RuntimeException("Cannot map class");
    //    }

}
